package com.zzptc.zzsgz.bdsjws.fragments;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.adapter.Add_Contacts_Adapter;
import com.zzptc.zzsgz.bdsjws.fragments.base.BaseFragment;
import com.zzptc.zzsgz.bdsjws.utils.SelectContacts;
import com.zzptc.zzsgz.bdsjws.vo.Contacts;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.R.id.list;

/**
 * Created by Administrator on 2017/6/6.
 */

public class ShowAllcontacts extends BaseFragment {

    private RecyclerView recyclerView;
    private static List<Contacts> list;

    @Override
    public int getXML() {
        return R.layout.show_all_contacts_layout;
    }

    @Override
    public void initView() {
    }

    @Override
    public void initDate() {
        list = MyApplication.contacts_list;
        recyclerView = (RecyclerView) getThisView().findViewById(R.id.recyclerview_show_contacts);
        recyclerView.setLayoutManager(new LinearLayoutManager(MyApplication.getContext()));
        Add_Contacts_Adapter add_contacts_adapter=new Add_Contacts_Adapter(list);
        recyclerView.setAdapter(add_contacts_adapter);
    }

    public static List search(String name) {
        List<Contacts> results=new ArrayList<>();
//        Pattern pattern = Pattern.compile(name);
//        for(int i=0; i < list.size(); i++){
//            Matcher matcher = pattern.matcher(((Contacts)list.get(i))._name);
//            Matcher matcher2 = pattern.matcher(((Contacts)list.get(i))._tel);
//            if(matcher.find()||matcher2.find()){
//                results.add(list.get(i));
//            }
//        }
//        return results;
        Contacts contacts;
        for (int j = 0; j < list.size(); j++) {
            contacts=list.get(j);
            if(contacts._name.replace(" ","").replace("-","").contains(name)||contacts._tel.replace(" ","").replace("-","").contains(name)){
                results.add(contacts);
            }
        }
        return results;
    }
}
